from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        cap={
            "platformName": "Android",
            "deviceName": "emulator-5554",
            "noReset": True,
            "appPackage": "com.xiachufang",
            "appActivity": "com.xiachufang.activity.home.HomeActivity"
        }
        # 隐式等待
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(20)

    # 定位元素
    def dingwei(self,loc):
        ele=self.driver.save_screenshot(*loc)
        return ele
    # 显示等待
    def xianshi(self,loc):
        ele=WebDriverWait(self.driver,200).until(EC.element_attribute_to_include(loc))
        return ele
    # 截图
    def jietu(self,loc):
        self.driver.save_screenshot(loc)

    # 滑动
    def huadong(self,x,y,x2,y2):
        self.driver.swipe(x,y,x2,y2)
    # 轻敲
    def qingqiao(self,x,y):
        self.driver.tap([(x,y)],200)
    # 退出
    def tuichu(self):
        self.driver.quit()
    # 系统按键
    def xitonganjian(self):
        self.driver.press_keycode(3)
